_require "basis.smi"
_require "base.sig"
_require "utils.sig"
_require "sigs.sml"

functor ShrinkLrTableFun(
  A : sig
    structure LrTable : sig
      datatype ('a,'b) pairlist = EMPTY | PAIR of 'a * 'b * ('a,'b) pairlist
      datatype state = STATE of int
      datatype term = T of int
      datatype nonterm = NT of int
      datatype action = SHIFT of state | REDUCE of int | ACCEPT | ERROR
      type table
      val numStates : table -> int
      val numRules : table -> int
      val describeActions : table -> state -> (term,action) pairlist * action
      val describeGoto : table -> state -> (nonterm,state) pairlist
      val action : table -> state * term -> action
      val goto : table -> state * nonterm -> state
      val initialState : table -> state
      exception Goto of state * nonterm
      val mkLrTable : {actions : ((term,action) pairlist * action) array,
                       gotos : (nonterm,state) pairlist array,
                       numStates : int, numRules : int,
                       initialState : state} -> table
    end
  end
) =
struct
  structure LrTable =
  struct
    datatype pairlist = datatype A.LrTable.pairlist
    datatype state = datatype A.LrTable.state
    datatype term = datatype A.LrTable.term
    datatype nonterm = datatype A.LrTable.nonterm
    datatype action = datatype A.LrTable.action
    type table = A.LrTable.table
    val numStates : table -> int
    val numRules : table -> int
    val describeActions : table -> state -> (term,action) pairlist * action
    val describeGoto : table -> state -> (nonterm,state) pairlist
    val action : table -> state * term -> action
    val goto : table -> state * nonterm -> state
    val initialState : table -> state
    exception Goto = A.LrTable.Goto
    val mkLrTable : {actions : ((term,action) pairlist * action) array,
                     gotos : (nonterm,state) pairlist array,
                     numStates : int, numRules : int,
                     initialState : state} -> table
  end
  val shrinkActionList : LrTable.table * bool ->
                         (int * int list *
                          ((LrTable.term,LrTable.action) LrTable.pairlist *
                           LrTable.action) list) * int
end
